package com.elm.serviceimpl;

import java.util.List;

import com.elm.dao.FoodDao;
import com.elm.daoimpl.FoodDaoImpl;
import com.elm.model.Food;
import com.elm.model.PageBean;
import com.elm.service.FoodService;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
/**

 * 

 * @author pgm

 * 

 */
public class FoodServiceImpl implements FoodService{
	FoodDao fdao = new FoodDaoImpl();
	@Override
	public Food getFoodbyFoodid(int foodid) {
		
		return fdao.getFoodbyFoodid(foodid);
	}
	@Override
	public List<Food> findAllfoodBySid(int sellerid,PageBean p) {
		// TODO Auto-generated method stub
		return fdao.findAllfoodBySid(sellerid,p);
	}
	@Override
	public int getFoodCount(int sellerid) {
		// TODO Auto-generated method stub
		return fdao.getFoodCount(sellerid);
	}
	public List<Food> getFoodbyFoodids(List<Integer> foodids) {
		
		return fdao.getFoodbyFoodids(foodids);
	}
	@Override
	public JSONObject getFood(int start, int pageSize, int sellerid) {
		// TODO Auto-generated method stub
		
		JSONObject fods=new JSONObject();
		fods.put("total", fdao.getFoodCount(sellerid));
		fods.put("rows",JSONArray.fromObject(fdao.getFoodBySellerid(sellerid, start, pageSize)));
		

		return fods;
	}

	@Override
	public JSONObject getFood(int start, int pageSize, int sellerid, String searchname) {
		// TODO Auto-generated method stub
		JSONObject fods=new JSONObject();
		fods.put("total", fdao.getFoodCount(sellerid));
		fods.put("rows", JSONArray.fromObject(fdao.getFoodBySellerid(sellerid, start, pageSize, searchname)));
		
		return fods;
	}

	@Override
	public int insertFood(Food f,int sellerid) {
		// TODO Auto-generated method stub
		int flag=0;
		flag=fdao.insertFood(f, sellerid);
		return flag;
	}

	@Override
	public int updateFood(Food f) {
		// TODO Auto-generated method stub
		int flag=0;
		flag=fdao.updateFood(f);
		return flag;
	}

	@Override
	public boolean deleteFood(String arr) {
		// TODO Auto-generated method stub
		boolean flag=false;
		flag=fdao.deleteFood(arr);
		return flag;
	}

}
